//
// Created by Jisam on 2024/6/30.
//
#include <bits/stdc++.h>

#define i64 long long
using namespace std;
const int N = 50 + 5;
char a[N][N];
int ans = INT_MAX,i,j ,k, l;
int m, n;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n >> m;
    for (i = 1; i <= n; i++) {
        for (j = 1; j <= m; j++) {
            cin >> a[i][j];
        }
    }


    for (i = 1; i <= n - 2; i++) {
        for (j = i + 1; j <= n - 1; j++) {
            int mi = 0;
            for (k = 1; k <= i; k++) {
                for (l = 1; l <= m; l++) {
                    if (a[k][l] != 'W') mi++;
                }
            }
            for (k = i + 1; k <= j; k++) {
                for (l = 1; l <= m; l++) {
                    if (a[k][l] != 'B') mi++;
                }
            }
            for (k = j + 1; k <= n; k++) {
                for (l = 1; l <= m; l++) {
                    if (a[k][l] != 'R') mi++;
                }
            }
            ans = min(ans , mi);
        }
    }
    cout << ans <<"\n";
    return 0;
}